#!/bin/bash
scriptWorkd=$(cd "$(dirname $0)";pwd)

### ========= 全局变量 ===========
    sysType=$(awk -F= '/^ID=/{print $2}' /etc/os-release)
    sysVer=$(awk -F= '/^VERSION_ID=/{print $2}' /etc/os-release)
    sysVer=${sysVer#\"}
    sysVer=${sysVer%\"}
### ==============================

### ========= 前置文件 ===========
if [[ -f ${HOME}/bin/basic_func.sh ]];then  ### 存在才载入
    source ${HOME}/bin/basic_func.sh
elif [[ -f ./bin/basic_func.sh ]];then
    source ./bin/basic_func.sh
elif [[ -f ../bin/basic_func.sh ]];then
    source ../bin/basic_func.sh
fi
### ==============================


function main() {
set +e
    ## 开始信息
    echo -e "${blue4}\n$(basename $0)\n${normal}"
    echo -e "${hintStrProcessing}Installing Common Deb pkg (It can work when 2025.03.08, for Ubuntu.24.04)${normal}"

    last_dir=$(pwd)
    mkdir -p ${HOME}/Downloads/common-deb
    cd ${HOME}/Downloads/common-deb
    echo -e "${hintStrProcessing}Installing VSCode"
    ## vscode
    wget -O code_1.98.0-1741124782_amd64.deb https://vscode.download.prss.microsoft.com/dbazure/download/stable/6609ac3d66f4eade5cf376d1cb76f13985724bcb/code_1.98.0-1741124782_amd64.deb
    echo "code code/add-microsoft-repo boolean true" | sudo debconf-set-selections
    sudo apt install ./code_1.98.0-1741124782_amd64.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}VSCode Installed"
    else
        echo -e "${hintStrFailed}VSCode Not Installed"
    fi


    ## 微信
    echo -e "${hintStrProcessing}Installing WeChat"
    wget -O WeChatLinux_x86_64.deb https://dldir1v6.qq.com/weixin/Universal/Linux/WeChatLinux_x86_64.deb
    sudo apt install ./WeChatLinux_x86_64.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}WeChat Installed"
    else
        echo -e "${hintStrFailed}WeChat Not Installed"
    fi

    ## QQ
    echo -e "${hintStrProcessing}Installing QQ"
    wget -O QQ_3.2.16_250307_amd64_01.deb https://dldir1.qq.com/qqfile/qq/QQNT/Linux/QQ_3.2.16_250307_amd64_01.deb
    sudo apt install ./QQ_3.2.16_250307_amd64_01.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}QQ Installed"
    else
        echo -e "${hintStrFailed}QQ Not Installed"
    fi

    ## edge
    echo -e "${hintStrProcessing}Installing Edge"
    wget -O microsoft-edge-stable_134.0.3124.51-1_amd64.deb https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-stable/microsoft-edge-stable_134.0.3124.51-1_amd64.deb?brand=M102
    sudo apt install ./microsoft-edge-stable_134.0.3124.51-1_amd64.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}Edge Installed"
    else
        echo -e "${hintStrFailed}Edge Not Installed"
    fi

    ## Obsidian
    echo -e "${hintStrProcessing}Installing Obsidian"
    githubDownload obsidianmd/obsidian-releases/releases/download/v1.8.9/obsidian_1.8.9_amd64.deb
    sudo apt install ./obsidian_1.8.9_amd64.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}Obsidian Installed"
    else
        echo -e "${hintStrFailed}Obsidian Not Installed"
    fi

    
    ## VPN:Hiddify
    if version_lt ${sysVer} 24.00;then
        echo -e "${hintStrWarning}Hiddify may unable to install"
    fi
    echo -e "${hintStrProcessing}Installing Hiddify(VPN)"
    githubDownload hiddify/hiddify-app/releases/download/v2.5.7/Hiddify-Debian-x64.deb
    sudo apt install ./Hiddify-Debian-x64.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}Hiddify Installed"
    else
        echo -e "${hintStrFailed}Hiddify Not Installed"
    fi

    ## Zotero
    if version_lt ${sysVer} 24.00;then
        echo -e "${hintStrWarning}Zotero may unable to install"
    fi
    echo -e "${hintStrProcessing}Installing Zotero"
    sudo snap install Zotero
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}Zotero Installed"
    else
        echo -e "${hintStrFailed}Zotero Not Installed"
    fi

    
    if version_lt ${sysVer} 24.00;then
        echo -e "${hintStrWarning}Hiddify may unable to install"
    fi
    echo -e "${hintStrProcessing}Installing Hiddify(VPN)"
    githubDownload hiddify/hiddify-app/releases/download/v2.5.7/Hiddify-Debian-x64.deb
    wget -O utools_6.1.0_amd64.deb https://open.u-tools.cn/download/utools_6.1.0_amd64.deb
    sudo apt install ./utools_6.1.0_amd64.deb
    if [[ $? == 0 ]];then
        echo -e "${hintStrSucceed}Utools Installed"
    else
        echo -e "${hintStrFailed}Utools Not Installed"
    fi

    ## CherryStudio
    echo -e "${hintStrProcessing}Downloading CherryStudio"
    wget -O Cherry-Studio-1.0.0-x86_64.AppImage https://download-cf.ocoolai.com/https://github.com/CherryHQ/cherry-studio/releases/download/v1.0.0/Cherry-Studio-1.0.0-x86_64.AppImage

    cd ${last_dir}

    ## 结束信息
    echo -e "${green4}\n$(basename $0)\n${normal}"
}
main $@


# VSCode Download:https://code.visualstudio.com/docs/?dv=linux64_deb
